﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Data.Odbc.Core
{
    public class Pool : IDisposable
    {
        private ThreadPool m_pool;
        public int Count { get { return m_pool != null ? m_pool.Count : 0; } }
        public Pool(int capactity)
        {
            m_pool = new ThreadPool(capactity);
        }
        public Args.PoolArgs Pop()
        {
            return m_pool.Pop();
        }

        public void Push(Args.PoolArgs args)
        {
            m_pool.Push(args);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                foreach (Args.PoolArgs p in m_pool.GetPools)
                {
                    ((System.Data.Odbc.OdbcConnection)p.handle).Close();
                    ((System.Data.Odbc.OdbcConnection)p.handle).Dispose();
                }
                m_pool.Dispose();
                GC.SuppressFinalize(this);
            }
        }
        public void Dispose()
        {
            m_pool.Dispose();
        }
    }
}
